package service

import (
	"context"
	"user-service/basic/config"
	__ "user-service/basic/proto"
	"user-service/handler/model"
)

func (s *Server) DockerList(_ context.Context, in *__.DockerListReq) (*__.DockerListResp, error) {

	var dockers []model.Docker
	config.DB.Where("hospital_id=?", in.HospitalId).Where("qualification_status=?", in.Status).Where("docker_name like ?", in.DockerName).Find(&dockers)
	var hospitallist []*__.DockerList
	for _, m := range dockers {
		list := __.DockerList{
			DockerName: m.DockerName,
			HospitalId: m.HospitalId,
			Title:      m.Title,
			Specialty:  m.Specialty,
			Phone:      m.Phone,
			LicenseNo:  m.LicenseNo,
		}
		hospitallist = append(hospitallist, &list)
	}
	return &__.DockerListResp{
		List: hospitallist,
	}, nil
}

func (s *Server) DockerDetail(_ context.Context, in *__.DockerDetailReq) (*__.DockerDetailResp, error) {
	var dockers model.Docker
	config.DB.Where("id=?", in.Id).Find(&dockers)

	return &__.DockerDetailResp{
		DockerName: dockers.DockerName,
		HospitalId: dockers.HospitalId,
		Title:      dockers.Title,
		Specialty:  dockers.Specialty,
		Phone:      dockers.Phone,
		LicenseNo:  dockers.LicenseNo,
	}, nil
}
